﻿
using RazorEngine;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using RazorEngine.Templating;

namespace Asion.VSIX.Code.Create.Core.FrameWork
{
    /// <summary>
    /// razor template utils
    /// </summary>
    public class TemplateFactory
    {

        /*
            --relation document
            https://github.com/sebastienros/fluid/tree/main
            https://www.coderbusy.com/liquid/tags/iteration/
            https://github.com/fouadmess/RazorEngine

            --如果新增模型需要使用才可以正常的渲染数据
              context.Options.MemberAccessStrategy.Register<ParameterGenerative>();
         */

        //private FluidParser parser = null;

        /// <summary>
        /// 初始化 模版
        /// </summary>
        /// <param name="filePath"></param>
        public TemplateFactory()
        {
            // parser = new FluidParser(); 

            //初始化模版


        }







        /// <summary>
        /// 渲染数据
        ///
        /// </summary>
        /// <param name="data"></param>
        public string Render(string key, string templdate, object data)
        {
        
             Engine.Razor.RunCompile(templdate, key, typeof(ClassGenerative), data);
            /*if (parser.TryParse(templdate, out var template, out var error))
            {
               return template.Render(context);
            }
            else {
                throw new Exception("模版数据异常");
            } */
            var result = Engine.Razor.Run(key, typeof(ClassGenerative), data);
            return result;
        }
    }
}
